// Diamond inherit

#include <iostream>
#include <cstring>
using namespace std;

class A { // virtual Basic class
public:
	int m_a;
};

class X : virtual public A { // Middle subclass
	public:
		int m_x;
		void setAge( int age ) {
			this->m_a = age;
			// 1.this	2.middle
			// 3.ptr	4.offset
			// 5.this+offset
			// 6.A::m_a
		}
};

class Y : virtual public A { // Middle subclass
	public:
		int m_y;
		int getAge( ) {
			return this->m_a;
			// 1.this	2.middle
			// 3.ptr	4.offset
			// 5.this+offset
			// 6.A::m_a
		}
};

class Z : public X, public Y { // Aggregation subclass
	public:
		int m_z;
		void foo( ) {
			m_a = 100;
		}
};

// designer
// ------------------------------------------------------------------
// user

int main( void ) { 
	Z z;	// | X | Y | m_z | virtual class |  -->  | ptr  m_x | ptr m_y | m_z | m_a |
	cout << "sizeof( z )  = "  << sizeof( z ) << endl; // 40
	z.m_a = 100;
	z.setAge( 28 );
	cout << z.getAge( ) << endl;

	return 0;
}

